import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-07-12
 * Time: 17:12
 */
class Student implements Comparable<Student>{
    public int age;

    @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }

    public Student(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                '}';
    }
}
public class Test {
    public static void main(String[] args) {
        TestHeap testHeap=new TestHeap();
        int[] array={27,15,19,18,28,34,65,49,25,37};
        testHeap.createHeap(array);
        testHeap.heapSort();
        System.out.println("hh");
    }
    public static int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        int[] topK=new int[k];
        if(k==0){
            return topK;
        }
        for(int i=0;i<k;i++){
            priorityQueue.offer(arr[i]);
        }
        for(int i=k;i<arr.length;i++){
            if(arr[i]<priorityQueue.peek()){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        for(int i=0;i<k;i++){
            topK[i]=priorityQueue.poll();
        }
        return topK;
    }

    public static void main4(String[] args) {
        int[] array={27,15,19,18,28,34,65,49,25,37};
        System.out.println(Arrays.toString(smallestK(array, 3)));
    }
    public static void main3(String[] args) {
        PriorityQueue<Student> priorityQueue=new PriorityQueue<>();
        priorityQueue.offer(new Student(12));
        priorityQueue.offer(new Student(2));
        System.out.println(priorityQueue);
    }
    public static void main2(String[] args) {
        //大根堆
        PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

    }
    public static void main1(String[] args) {
        TestHeap testHeap=new TestHeap();
        int[] array={27,15,19,18,28,34,65,49,25,37};
        testHeap.createHeap(array);
        testHeap.push(80);
        System.out.println("hah");
        System.out.println(testHeap.pollHeap());
    }
}
